package com.share.tool.devops.controller;

import com.share.common.common.Result;
import com.share.tool.devops.model.es.EsLogPage;
import com.share.tool.devops.model.es.EsLogReq;
import com.share.tool.devops.service.EsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;
import java.util.Set;


@RestController
public class EsController {

    @Autowired
    private EsService esService;

    @ResponseBody
    @RequestMapping(value = "/listIndex")
    public Result listIndex() {
        return Result.success(esService.listIndex());
    }

    @ResponseBody
    @RequestMapping(value = "/listLevel")
    public Result listLevel() {
        Set<String> sets = new HashSet<>();
        sets.add("INFO");
        sets.add("ERROR");
        return Result.success(sets);
    }

    @ResponseBody
    @RequestMapping(value = "/listApplicationName")
    public Result listApplicationName(EsLogReq req) {
        return Result.success(esService.listApplicationName(req));
    }

    @ResponseBody
    @RequestMapping(value = "/listIp")
    public Result listIp(EsLogReq req) {
        return Result.success(esService.listIp(req));
    }

    @ResponseBody
    @RequestMapping(value = "/listApplicationNameAndIp")
    public Result listApplicationNameAndIp(EsLogReq req) {
        return Result.success(esService.listApplicationNameAndIp(req));
    }

    @RequestMapping(value = "/listClasspath")
    public Result listClasspath(EsLogReq req) {
        return Result.success(esService.listClasspath(req));
    }

    @RequestMapping(value = "/pageList")
    public Result pageList(EsLogReq req) {
        EsLogPage pages = esService.pageList(req);
        return Result.success(pages);
    }
}
